package com.gitee.wsl.mathematics.geometry.d2.base

import com.gitee.wsl.io.dataproxy.DataProxy
import com.gitee.wsl.io.dataproxy.asProxy
import com.gitee.wsl.mathematics.number.FloatCalcContainer
import com.gitee.wsl.mathematics.vector.MutableVector

interface MarginAble<T:Number>:MutableVector<T, MarginAble<T>> {
    val top: T     get() = proxy[0]
    val right: T   get() = proxy[1]
    val bottom: T  get() = proxy[2]
    val left: T    get() = proxy[3]

    override var length :T get() = zero ;set(value){  }
    override val squaredLength get() = zero

    override val isNotZero: Boolean get() = top != zero || left != zero || right != zero || bottom != zero

    val leftPlusRight get() = left + right
    val topPlusBottom get() = top + bottom

    val horizontal get() = (left + right) / 2
    val vertical  get() = (top + bottom) / 2

}

class Margin(
    top: Float,
    right: Float,
    bottom: Float,
    left: Float,
    override val proxy:DataProxy<Float> = arrayOf(top,right,bottom,left).asProxy()
) : MarginAble<Float>,FloatCalcContainer{

    override fun create(values: List<Float>) = Margin(values[0],values[1],values[2],values[3])

    override val self
        get() = this

    override fun toString(): String = "Margin(top=${top}, right=${right}, bottom=${bottom}, left=${bottom}"
   
  companion object{
      val ZERO = Margin(0.0f, 0.0f, 0.0f, 0.0f)
      inline operator fun invoke(margin: Number): Margin = Margin(margin.toFloat(), margin.toFloat(), margin.toFloat(), margin.toFloat())
      inline operator fun invoke(vertical: Number, horizontal: Number): Margin = Margin(vertical.toFloat(), horizontal.toFloat(), vertical.toFloat(), horizontal.toFloat())
      inline operator fun invoke(top: Number, right: Number, bottom: Number, left: Number): Margin = Margin(top.toFloat(), right.toFloat(), bottom.toFloat(), left.toFloat())
  }
}
